package com.tencent.web.controller;

import com.github.pagehelper.PageInfo;
import com.tencent.entity.Pagination;
import com.tencent.entity.Result;
import com.tencent.entity.SetMeal;
import com.tencent.service.SelMealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


@RestController
@RequestMapping("/setmeal")
public class SelMealController {
    @Autowired
    private SelMealService selMealService;
    @RequestMapping("/add")
    public int add(SetMeal setMeal ){
        setMeal.setName("大套餐");
        setMeal.setCode("0008");
        setMeal.setHelpCode("ZZZZ");
        setMeal.setSex((char) 1);
        setMeal.setAge("20");
        setMeal.setPrice(200f);
        setMeal.setRemark("大套餐");
        int add1 = selMealService.add(setMeal);
        return  add1;

    }


    @RequestMapping ("/addOne")
    public int addHandle(@RequestBody SetMeal setMeal){
        return selMealService.add(setMeal);
    }
    @GetMapping("/findall")
    public List<SetMeal> findAll(){

        return selMealService.findAll();
    }
    @PostMapping("/delect")
    public  int delect(String code){
        return  selMealService.deleteByCode(code);
    }

    @GetMapping("/findbycode")
    public  Result findByCode(Pagination pagination){
        PageInfo<SetMeal> PageInfo = selMealService.findByCode(pagination);
//        Result result = new Result(true, "ok", PageInfo);
        return  Result.success(PageInfo);
    }
    @RequestMapping("/updata")
    public int updataSetmeal(SetMeal setMeal){
        return selMealService.updateSetmeal(setMeal);
    }
}
